from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-26 14:12:16.913606
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 26, Sep, 2021
Time: 14:12:21
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3756
Nobs: 426.000 HQIC: -46.8938
Log likelihood: 4710.24 FPE: 3.07162e-21
AIC: -47.2322 Det(Omega_mle): 2.49273e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.424542 0.091742 4.628 0.000
L1.Burgenland 0.105326 0.047487 2.218 0.027
L1.Kärnten -0.113870 0.023822 -4.780 0.000
L1.Niederösterreich 0.160874 0.101857 1.579 0.114
L1.Oberösterreich 0.118569 0.100078 1.185 0.236
L1.Salzburg 0.284050 0.050011 5.680 0.000
L1.Steiermark 0.027278 0.066650 0.409 0.682
L1.Tirol 0.106907 0.052511 2.036 0.042
L1.Vorarlberg -0.103949 0.047119 -2.206 0.027
L1.Wien -0.003509 0.091255 -0.038 0.969
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011391 0.210071 0.054 0.957
L1.Burgenland -0.050618 0.108737 -0.466 0.642
L1.Kärnten 0.037133 0.054548 0.681 0.496
L1.Niederösterreich -0.209841 0.233234 -0.900 0.368
L1.Oberösterreich 0.485626 0.229160 2.119 0.034
L1.Salzburg 0.307646 0.114515 2.687 0.007
L1.Steiermark 0.108224 0.152615 0.709 0.478
L1.Tirol 0.312817 0.120240 2.602 0.009
L1.Vorarlberg 0.002363 0.107894 0.022 0.983
L1.Wien 0.006826 0.208958 0.033 0.974
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242310 0.046446 5.217 0.000
L1.Burgenland 0.092151 0.024042 3.833 0.000
L1.Kärnten -0.001882 0.012061 -0.156 0.876
L1.Niederösterreich 0.211619 0.051568 4.104 0.000
L1.Oberösterreich 0.159557 0.050667 3.149 0.002
L1.Salzburg 0.034907 0.025319 1.379 0.168
L1.Steiermark 0.021638 0.033743 0.641 0.521
L1.Tirol 0.069134 0.026585 2.600 0.009
L1.Vorarlberg 0.059154 0.023855 2.480 0.013
L1.Wien 0.112867 0.046200 2.443 0.015
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185319 0.045538 4.070 0.000
L1.Burgenland 0.046375 0.023571 1.967 0.049
L1.Kärnten -0.006582 0.011825 -0.557 0.578
L1.Niederösterreich 0.141597 0.050559 2.801 0.005
L1.Oberösterreich 0.316266 0.049676 6.367 0.000
L1.Salzburg 0.100724 0.024824 4.058 0.000
L1.Steiermark 0.129160 0.033083 3.904 0.000
L1.Tirol 0.077686 0.026065 2.980 0.003
L1.Vorarlberg 0.056113 0.023389 2.399 0.016
L1.Wien -0.046749 0.045297 -1.032 0.302
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203477 0.090196 2.256 0.024
L1.Burgenland -0.045225 0.046688 -0.969 0.333
L1.Kärnten -0.034022 0.023421 -1.453 0.146
L1.Niederösterreich 0.110938 0.100142 1.108 0.268
L1.Oberösterreich 0.164063 0.098393 1.667 0.095
L1.Salzburg 0.251252 0.049168 5.110 0.000
L1.Steiermark 0.078897 0.065527 1.204 0.229
L1.Tirol 0.125238 0.051627 2.426 0.015
L1.Vorarlberg 0.117461 0.046325 2.536 0.011
L1.Wien 0.031613 0.089719 0.352 0.725
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.033154 0.069582 0.476 0.634
L1.Burgenland 0.023764 0.036017 0.660 0.509
L1.Kärnten 0.054205 0.018068 3.000 0.003
L1.Niederösterreich 0.208227 0.077254 2.695 0.007
L1.Oberösterreich 0.339409 0.075905 4.472 0.000
L1.Salzburg 0.045122 0.037931 1.190 0.234
L1.Steiermark -0.009274 0.050551 -0.183 0.854
L1.Tirol 0.112149 0.039827 2.816 0.005
L1.Vorarlberg 0.069973 0.035738 1.958 0.050
L1.Wien 0.124160 0.069213 1.794 0.073
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195618 0.085259 2.294 0.022
L1.Burgenland 0.016014 0.044132 0.363 0.717
L1.Kärnten -0.057237 0.022139 -2.585 0.010
L1.Niederösterreich -0.116517 0.094660 -1.231 0.218
L1.Oberösterreich 0.193672 0.093006 2.082 0.037
L1.Salzburg 0.033253 0.046477 0.715 0.474
L1.Steiermark 0.285304 0.061940 4.606 0.000
L1.Tirol 0.491084 0.048800 10.063 0.000
L1.Vorarlberg 0.076238 0.043789 1.741 0.082
L1.Wien -0.114658 0.084807 -1.352 0.176
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158410 0.093137 1.701 0.089
L1.Burgenland -0.011266 0.048210 -0.234 0.815
L1.Kärnten 0.063542 0.024184 2.627 0.009
L1.Niederösterreich 0.192475 0.103406 1.861 0.063
L1.Oberösterreich -0.125508 0.101600 -1.235 0.217
L1.Salzburg 0.234505 0.050771 4.619 0.000
L1.Steiermark 0.151216 0.067663 2.235 0.025
L1.Tirol 0.049112 0.053309 0.921 0.357
L1.Vorarlberg 0.131018 0.047836 2.739 0.006
L1.Wien 0.158699 0.092643 1.713 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.482787 0.050568 9.547 0.000
L1.Burgenland -0.006896 0.026175 -0.263 0.792
L1.Kärnten -0.009671 0.013131 -0.737 0.461
L1.Niederösterreich 0.204593 0.056143 3.644 0.000
L1.Oberösterreich 0.254284 0.055163 4.610 0.000
L1.Salzburg 0.022776 0.027566 0.826 0.409
L1.Steiermark -0.023583 0.036737 -0.642 0.521
L1.Tirol 0.068066 0.028944 2.352 0.019
L1.Vorarlberg 0.060104 0.025972 2.314 0.021
L1.Wien -0.049764 0.050300 -0.989 0.322
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022509 0.077182 0.140782 0.133083 0.042781 0.073561 0.001495 0.183014
Kärnten 0.022509 1.000000 -0.044172 0.128757 0.047325 0.071432 0.453850 -0.090726 0.090916
Niederösterreich 0.077182 -0.044172 1.000000 0.282054 0.082224 0.268940 0.019636 0.137097 0.260689
Oberösterreich 0.140782 0.128757 0.282054 1.000000 0.176963 0.289811 0.156374 0.102402 0.138858
Salzburg 0.133083 0.047325 0.082224 0.176963 1.000000 0.124834 0.056195 0.106644 0.051259
Steiermark 0.042781 0.071432 0.268940 0.289811 0.124834 1.000000 0.131163 0.094013 -0.016481
Tirol 0.073561 0.453850 0.019636 0.156374 0.056195 0.131163 1.000000 0.046763 0.118750
Vorarlberg 0.001495 -0.090726 0.137097 0.102402 0.106644 0.094013 0.046763 1.000000 -0.047053
Wien 0.183014 0.090916 0.260689 0.138858 0.051259 -0.016481 0.118750 -0.047053 1.000000